package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.PageRequest;
import com.ytjj.qmyx.admin.service.CopywriterConfigService;
import com.ytjj.qmyx.mall.model.CopywriterConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文案配置
 */
@RestController
@RequestMapping("/copyWriterConfig")
public class CopywriterConfigController {
    @Autowired
    private CopywriterConfigService copywriterConfigService;
    /**
     * 文案列表
     * @return
     */
    @PostMapping("/list")
    public CommonResult list (@RequestBody PageRequest pageRequest){
        CommonPage<CopywriterConfig> page = copywriterConfigService.list(pageRequest);
        return CommonResult.success(page);
    }

    /**
     * 新增文案
     */
    @PostMapping("/insert")
    public CommonResult insert (@RequestBody CopywriterConfig copywriterConfig){
        Integer count = copywriterConfigService.insert(copywriterConfig);
        if(count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * 修改文案
     */
    @PostMapping("/update")
    public CommonResult update (@RequestBody CopywriterConfig copywriterConfig){
        Integer count = copywriterConfigService.update(copywriterConfig);
        if(count>0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
